/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package table.model;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import obj.UpdateHistory;

/**
 *
 * @author Omar
 */
public class UpdateTableModel extends AbstractTableModel {

    String[] columnNames = {  "Table Name", "Table ID", "Field Name", "Action"
                            , "Old Value", "New Value" , "Timestamp"};
    ArrayList<UpdateHistory> updateHistory;

    public UpdateTableModel() {
        updateHistory = new ArrayList<UpdateHistory>();
    }
    
    
    
    @Override
    public int getRowCount() {
        return updateHistory.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex) {
            case 0: //column names
                return updateHistory.get(rowIndex).getTableName();
            case 1:
                return updateHistory.get(rowIndex).getTableID();
            case 2: 
                return updateHistory.get(rowIndex).getFieldName();
            case 3: 
                return updateHistory.get(rowIndex).getAction();
            case 4:
                return updateHistory.get(rowIndex).getOldValue();
            case 5: 
                return updateHistory.get(rowIndex).getNewValue();
            case 6: 
                return updateHistory.get(rowIndex).getTimestamp();
            default:
                return null;
        }
    }
    
    public void addUpdateHistory(UpdateHistory history) {
        updateHistory.add(history);
    }
    
}
